<%@ page pageEncoding="utf-8"%>
<%@page import="org.myhibernate.util.Json"%>
<%@page import="org.myhibernate.Template"%>
<%@page import="org.myhibernate.ProxyTemplate"%>
<%@page import="org.myhibernate.core.method.PageSizeQuery"%>
<%@page import="org.personal.entity.Page"%>
<%@page import="org.personal.entity.Layout"%>
<%@page import="org.personal.entity.User"%>
<%@page import="org.personal.Constants"%>
<%@page import="org.personal.entity.UserPage"%>
<%@page import="org.personal.util.UserUtil"%>
<%@page import="org.personal.entity.Portlet"%>
<%
User user=(User)request.getSession().getAttribute(Constants.USER);
Json json=new Json();
if(user!=null)
{
	String pageId=request.getParameter("pageId");
	String info=request.getParameter("info");
	Template template=new ProxyTemplate(UserPage.class).getInstance();
	try
	{
		UserPage userPage=null;
		PageSizeQuery query=template.getPageSizeQuery();
		int count=0;
		boolean isCreate=false;
		count=query.query(" where userId='"+user.getUid()+"' and pageId="+pageId+" ");
		if(count>0)
		{
			userPage=(UserPage)query.getListObject(0,1).get(0);
		}else
		{
			userPage=new UserPage();
			userPage.setPageId(Integer.parseInt(pageId));
			userPage.setUserId(user.getUid());
			isCreate=true;		
		}
		userPage.getPortlets().clear();
		String[] ss=info.split(";");
		for(int i=0;i<ss.length;i++)
		{
			userPage.getPortlets().add(ss[i]);
		}
		
		if(isCreate)
		{
			template.save(userPage);
		}else
		{
			template.update(userPage,new String[]{"portlets"});
		}
		json.add("result","ok");
	}catch(Exception exception)
	{
		json.add("result","no");
		json.add("message",exception.toString().trim());
	}
	finally
	{
		template.close();
	}
}else
{
	json.add("result","no");
	json.add("message","用户未登录");
}
out.println(json);
%>
